using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace SystemScanner.ClientServices
{
	public class WmiService
	{

		public static IEnumerable<ManagementBaseObject> GetInstancesOfClass(string className)
		{
			var managementClass = new ManagementClass(className);
			foreach (var item in managementClass.GetInstances())
			{
				yield return item;
			}
		}
		public static IEnumerable<ManagementObject> ExecuteQuery(ObjectQuery query)
		{
			ManagementScope scope;
			ConnectionOptions options = new ConnectionOptions();
			options.Impersonation = ImpersonationLevel.Impersonate;
			scope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", Environment.MachineName), options);
			scope.Connect();
			ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
			foreach (ManagementObject queryObj in searcher.Get())
			{
				yield return queryObj;
				//queryResultProcessor(queryObj);
			}
		}
	}
}
